package com.liliudong.rommath.biz.sys.entity;

import com.liliudong.rommath.biz.sys.param.SysMenuAddParam;
import com.liliudong.rommath.biz.sys.param.SysMenuModifyParam;
import com.liliudong.rommath.common.base.IdBaseEntity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.EnumValue;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldNameConstants;

/**
 * 系统菜单 实体类。
 *
 * @author liudong.li
 * @since 1.0.0
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Table(value = "sys_menu")
@FieldNameConstants
public class SysMenu extends IdBaseEntity {

    /**
     * 父级id
     */
    @Column(value = "parent_id")
    private Long parentId;

    /**
     * 菜单类型 0代表菜单、1代表iframe、2代表外链、3代表按钮
     */
    @Column(value = "menu_type")
    private MenuType menuType;

    /**
     * 路由路径
     */
    @Column(value = "path")
    private String path;

    /**
     * 路由名称（必须保持唯一）
     */
    @Column(value = "name")
    private String name;

    /**
     * 路由重定向（默认跳转地址）
     */
    @Column(value = "redirect")
    private String redirect;

    /**
     * 菜单名称
     */
    @Column(value = "title")
    private String title;

    /**
     * 菜单图标
     */
    @Column(value = "icon")
    private String icon;

    /**
     * 是否在菜单中显示 0.否 1.是
     */
    @Column(value = "show_link")
    private Integer showLink;

    /**
     * 排序
     */
    @Column(value = "rank")
    private Integer rank;

    /**
     * 按需加载需要展示的页面
     */
    @Column(value = "component")
    private String component;

    /**
     * 菜单名称右侧的额外图标
     */
    @Column(value = "extra_icon")
    private String extraIcon;

    /**
     * 是否显示父级菜单
     */
    @Column(value = "show_parent")
    private Integer showParent;

    /**
     * 是否缓存该路由页面（开启后，会保存该页面的整体状态，刷新后会清空状态）
     */
    @Column(value = "keep_alive")
    private Integer keepAlive;

    /**
     * 需要内嵌的iframe链接地址
     */
    @Column(value = "frame_src")
    private String frameSrc;

    /**
     * 内嵌的iframe页面是否开启首次加载动画
     */
    @Column(value = "frame_loading")
    private Integer frameLoading;

    /**
     * 当前菜单名称或自定义信息禁止添加到标签页
     */
    @Column(value = "hidden_tag")
    private Integer hiddenTag;

    /**
     * 当前菜单名称或自定义信息固定添加到标签页
     */
    @Column(value = "fixed_tag")
    private Integer fixedTag;

    /**
     * 将某个菜单激活
     */
    @Column(value = "active_path")
    private String activePath;

    /**
     * 当前页面进场动画，比如 enterTransition: "animate__fadeInLeft"
     */
    @Column(value = "enter_transition")
    private String enterTransition;

    /**
     * 当前页面离场动画，比如 leaveTransition: "animate__fadeOutRight"
     */
    @Column(value = "leave_transition")
    private String leaveTransition;

    /**
     * 权限标识
     */
    @Column(value = "permission")
    private String permission;

    public static SysMenu of(SysMenuAddParam param) {
        SysMenu sysMenu = new SysMenu();
        sysMenu.setParentId(param.getParentId());
        sysMenu.setMenuType(param.getMenuType());
        sysMenu.setPath(param.getPath());
        sysMenu.setName(param.getName());
        sysMenu.setRedirect(param.getRedirect());
        sysMenu.setTitle(param.getTitle());
        sysMenu.setIcon(param.getIcon());
        sysMenu.setShowLink(param.getShowLink());
        sysMenu.setRank(param.getRank());
        sysMenu.setComponent(param.getComponent());
        sysMenu.setExtraIcon(param.getExtraIcon());
        sysMenu.setShowParent(param.getShowParent());
        sysMenu.setKeepAlive(param.getKeepAlive());
        sysMenu.setFrameSrc(param.getFrameSrc());
        sysMenu.setFrameLoading(param.getFrameLoading());
        sysMenu.setHiddenTag(param.getHiddenTag());
        sysMenu.setFixedTag(param.getFixedTag());
        sysMenu.setActivePath(param.getActivePath());
        sysMenu.setEnterTransition(param.getEnterTransition());
        sysMenu.setLeaveTransition(param.getLeaveTransition());
        sysMenu.setPermission(param.getPermission());
        return sysMenu;

    }

    public static SysMenu of(SysMenuModifyParam param) {
        SysMenu sysMenu = new SysMenu();
        sysMenu.setId(param.getId());
        sysMenu.setParentId(param.getParentId());
        sysMenu.setMenuType(param.getMenuType());
        sysMenu.setPath(param.getPath());
        sysMenu.setName(param.getName());
        sysMenu.setRedirect(param.getRedirect());
        sysMenu.setTitle(param.getTitle());
        sysMenu.setIcon(param.getIcon());
        sysMenu.setShowLink(param.getShowLink());
        sysMenu.setRank(param.getRank());
        sysMenu.setComponent(param.getComponent());
        sysMenu.setExtraIcon(param.getExtraIcon());
        sysMenu.setShowParent(param.getShowParent());
        sysMenu.setKeepAlive(param.getKeepAlive());
        sysMenu.setFrameSrc(param.getFrameSrc());
        sysMenu.setFrameLoading(param.getFrameLoading());
        sysMenu.setHiddenTag(param.getHiddenTag());
        sysMenu.setFixedTag(param.getFixedTag());
        sysMenu.setActivePath(param.getActivePath());
        sysMenu.setEnterTransition(param.getEnterTransition());
        sysMenu.setLeaveTransition(param.getLeaveTransition());
        sysMenu.setPermission(param.getPermission());
        sysMenu.setId(param.getId());
        return sysMenu;
    }

    /**
     * 菜单类型
     */
    @RequiredArgsConstructor
    @Getter
    public enum MenuType {
        /**
         * 菜单
         */
        MENU(0),
        /**
         * iframe
         */
        IFRAME(1),
        /**
         * 外链
         */
        LINK(2),
        /**
         * 按钮
         */
        BUTTON(3);

        @EnumValue
        private final int value;

    }

}
